
package com.netcracker.ui.util;

import java.util.List;
import com.netcracker.entity.Genre;

public class HtmlTreeModel {
    
    public static String contextPath = "";
    
    public static String getGenresTree(List<Genre> genresList,int lvl) {
        String resTree = tab(lvl)+"<ul>\n";
        for (Genre genre : genresList) {
            resTree += tab(lvl+1)+"<li>\n"+tab(lvl+2)+"<a href=\""+contextPath+"?action=findBook&type=byGenre&genreId="+genre.getId()+"\">" + genre.getName() + "</a>\n";
            if (genre.getSubGenres().size() > 0) {
                    resTree += getGenresTree(genre.getSubGenres(), lvl+2);
                }
            
            resTree += tab(lvl+1)+"</li>\n";
        }
        resTree += tab(lvl)+"</ul>\n";
        return resTree;
    }
    
    private static String tab(int lvl) {
        String t = "";
        for (int i = 0; i < lvl; i++) {
            t += "\t";
        }
        return t;
    }
    
  /*  public static String main(int lvl) {
        List<Genre> l1 = new ArrayList<>();
        List<Genre> l2 = new ArrayList<>();
        Genre g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11;
        g1 = new Genre(); g1.setName("R");
        g2 = new Genre(); g2.setName("r1");
        g3 = new Genre(); g3.setName("r2");
        g4 = new Genre(); g4.setName("r3");
        g5 = new Genre(); g5.setName("F");
        g6 = new Genre(); g6.setName("f1");
        g7 = new Genre(); g7.setName("f11");
        g8 = new Genre(); g8.setName("f12");
        g9 = new Genre(); g9.setName("D");
        g10 = new Genre(); g10.setName("d1");
        g11 = new Genre(); g11.setName("d11");
        
        g1.setChild(g2);
        g1.setChild(g3);
        g1.setChild(g4);
        g5.setChild(g6);
        g6.setChild(g7);
        g6.setChild(g8);
        g9.setChild(g10);
        g10.setChild(g11);
        l1.add(g1);
        l1.add(g5);
        l1.add(g9);
        return getGenresTree(l1, lvl);
    }*/
}